﻿using IcicleFramework.Collision;
using IcicleFramework.GameServices;

namespace IcicleFramework.Components.Collision
{
    public abstract class CollisionBehaviourComponent : BaseComponent, ICollisionBehaviourComponent
    {
        public CollisionBehaviourComponent()
        {}

        protected CollisionBehaviourComponent(CollisionBehaviourComponent old) 
            : base(old)
        {}

        public abstract void OnCollision(ICollisionComponent source, ICollisionComponent collided, CorrectionVector2 resolutionVector);

        public override void Initialize()
        {
            ICollisionManager collisionManager = GameServiceManager.GetService<ICollisionManager>();

            if (collisionManager != null && this.Parent != null)
                collisionManager.SubscribeCollisionEvent(this.Parent.GUID, OnCollision);

            base.Initialize();
        }
    }
}
